/**
 * 文件处理工具（极简版）
 */
import axios from 'axios'
import startNetwork from "./http";

const BASE_URL = 'http://localhost:8080/files/';
const AXIOS_URL  = "/api/files/"// 后端文件基础路径
const loginUser = JSON.parse(localStorage.getItem('loginUser'));

// 获取文件完整URL
export function getFileUrl(path) {
  if (!path) return '';
  return BASE_URL + path;
}

// 判断是否是图片
export function isImageFile(path) {
  if (!path) return false;
  return /\.(jpg|jpeg|png|gif|webp|bmp)$/i.test(path);
}


// 文件上传方法
export async function uploadFile(file) {

  let res = await startNetwork({
    url: AXIOS_URL + "upload",
    method: "POST",
    data: {
      file: file
    },
    headers: {
      'Content-Type': 'multipart/form-data',
      'token': loginUser.token
    }
  })
  return res;
}
